<% layout('/layouts/default.html', {title: '派单管理管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('派单管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('bis:bisDispatch:edit')){ %>
					<a href="${ctx}/bis/bisDispatch/form" class="btn btn-default btnTool" title="${text('新增派单管理')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
					<a href="#" id="btnExport" class="btn btn-default" title="${text('导出')}"><i class="glyphicon glyphicon-export"></i> ${text('导出')}</a>
				<% } %>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${bisDispatch}" action="${ctx}/bis/bisDispatch/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('订单号')}：</label>
					<div class="control-inline">
						<#form:input path="orderNo" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('派单类型')}：</label>
					<div class="control-inline">
						<#form:select path="dipatchType" dictType="dipatch_type" blankOption="true" blankOptionLabel="全部类型" class="form-control " />
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('状态')}：</label>
					<div class="control-inline width-120">
						<#form:select path="orderStatus" dictType="bis_dispatch_status" blankOption="true" blankOptionLabel="全部状态" class="form-control " />
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('省份')}：</label>
					<div class="control-inline">
							<#form:input path="city" maxlength="64" class="form-control" readonly="true"/>
							<#form:hidden path="cityId"/>
							<#form:input path="province" maxlength="64" class="form-control" readonly="true"/>
							<#form:hidden path="provinceId"/>
							<#form:treeselect id="area" title="选择区域"
							path="areaId" labelPath="area" url="${ctx}/sys/area/treeData" class="required"
							allowClear="true" canSelectRoot="false" canSelectParent="false" allowInput="false"
							callbackFuncName="areaTreeselectCallback"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('地址')}：</label>
					<div class="control-inline">
						<#form:input path="address" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('寄件人')}：</label>
					<div class="control-inline">
						<#form:input path="senderName" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('寄件人电话')}：</label>
					<div class="control-inline">
						<#form:input path="senderPhone" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('取件时间')}：</label>
					<div class="control-inline">
						<#form:input path="senderTime_gte" readonly="true" maxlength="20" class="form-control Wdate-date"
							dataFormat="date" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
						&nbsp;--&nbsp;
						<#form:input path="senderTime_lte" readonly="true" maxlength="20" class="form-control Wdate-date"
							dataFormat="date" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
					</div>
				</div>

				<div class="form-group">
					<label class="control-label">${text('选择快递员')}：</label>
					<div class="control-inline">
						<#form:treeselect id="assignorId" title="选择快递员"
						path="assignorId" labelPath="assignorName" url="${ctx}/bis/bisUser/treeData" class=""
						allowClear="true" canSelectRoot="true" canSelectParent="false" allowInput="false"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('备注信息')}：</label>
					<div class="control-inline">
						<#form:input path="remarks" maxlength="500" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("订单号")}', name:'id', index:'a.id', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
			return '<a href="${ctx}/bis/bisDispatch/form?id='+row.id+'" class="btnList" data-title="${text("编辑派单管理")}">'+(val||row.id)+'</a>';
		}},
		{header:'${text("派单类型")}', name:'dipatchType', index:'a.dipatch_type', width:120, align:"center", formatter: function(val, obj, row, act){
				return js.getDictLabel(${@DictUtils.getDictListJson('dipatch_type')}, val, '${text("未知")}', true);
			}},
		{header:'${text("状态")}', name:'orderStatus', index:'a.order_status', width:130, align:"center", formatter: function(val, obj, row, act){
			var action = '<a href="${ctx}/bis/bisDispatch/release?id='+row.id+'" class="btnList" title="${text("重新发布")}" data-confirm="${text("确认要重新发布吗？")}"><i class="fa fa-reply"></i></a>';
			return js.getDictLabel(${@DictUtils.getDictListJson('bis_dispatch_status')}, val, '${text("未知")}', true) + '&nbsp;' + (val == '5' ? action : '');
		}},
		{header:'${text("省")}', name:'province', index:'a.province', width:150, align:"left"},
		{header:'${text("城市")}', name:'city', index:'a.city', width:150, align:"left"},
		{header:'${text("区域")}', name:'area', index:'a.area', width:150, align:"left"},
		{header:'${text("地址")}', name:'address', index:'a.address', width:150, align:"left"},
		{header:'${text("寄件人")}', name:'senderName', index:'a.sender_name', width:80, align:"left"},
		{header:'${text("寄件人电话")}', name:'senderPhone', index:'a.sender_phone', width:150, align:"center"},
		{header:'${text("取件时间")}', name:'senderTime', index:'a.sender_time', width:150, align:"center"},
		{header:'${text("快递员")}', name:'assignorName', index:'a.assignor_name', width:150, align:"left"},
		{header:'${text("下单时间")}', name:'createDate', index:'a.create_date', width:150, align:"center"},
		{header:'${text("红包")}', name:'redPackets', index:'a.red_packets', width:150, align:"center",formatter:'currency', formatoptions:{thousandsSeparator:',', decimalSeparator:'.', decimalPlaces:2, defaulValue:'', prefix:'￥'}},
		{header:'${text("备注信息")}', name:'remarks', index:'a.remarks', width:150, align:"left"},
		{header:'${text("操作")}', name:'actions', width:120, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			<% if(hasPermi('bis:bisDispatch:edit')){ %>
				actions.push('<a href="${ctx}/bis/bisDispatch/form?id='+row.id+'" class="btnList" title="${text("编辑派单管理")}"><i class="fa fa-pencil"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/bis/bisDispatch/delete?id='+row.id+'" class="btnList" title="${text("删除派单管理")}" data-confirm="${text("确认要删除该派单吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
			<% } %>
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});

/**
 * 选择回调方法
 * @param id  标签的id
 * @param act 动作事件：ok、clear、cancel
 * @param index layer的索引号
 * @param layero layer内容的jQuery对象
 * @param nodes 当前选择的树节点数组
 */
function areaTreeselectCallback(id, act, index, layero, nodes){
	console.log(act);
	if (act === "ok"){
		if (nodes && nodes.length > 0){
			var node = nodes[0];
			$.ajax({
				url: "${ctx}/bis/bisDispatch/getArea",
				method: "post",
				dataType: "json",
				data: {areaId: node.id},
				success: function (res) {
					var area = res.data;
					var treeNames = area.treeNames;
					var parentCodes = area.parentCodes;
					var treeNamesAry = treeNames.split("/");
					var parentCodesAry = parentCodes.split(",");
					$("#provinceId").val(parentCodesAry[1]);
					$("#cityId").val(parentCodesAry[2]);
					$("#province").val(treeNamesAry[0]);
					$("#city").val(treeNamesAry[1]);
				}
			});
		}
	} else if(act === "clear"){
		$("#provinceId").val("");
		$("#cityId").val("");
		$("#province").val("");
		$("#city").val("");
	}
}
$("#city,#province").click(function(){
	$("#areaButton").trigger("click");
});
$('#btnExport').click(function(){
	js.ajaxSubmitForm($('#searchForm'), {
		url:'${ctx}/bis/bisDispatch/exportData',
		downloadFile:true
	});
});
</script>